package acs.bridge.jreport;

import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Collection;

//import sun.org.mozilla.javascript.internal.ObjToIntMap;

/**
 * acs.jreport
 * User: KuznetsovStV
 * Date: 25.12.11
 * Time: 13:48
 */
public class JReportSaveFile extends JReportFileUse implements JReportSaveInterface {


    public void setFilePath(String filePath) {
        this.filePath = filePath;
    }


    private String filePath;

    public String getReportName() {
        return fileName;
    }

    public void saveReportItem(Collection<JReportItem> jReportItemCollection) throws Exception {


        //String fullFileName = getFullFileName(jReportItem.getReportExt());

        byte[] outdata = archiveReport(jReportItemCollection);

        //fullFileName = getFullFileName((utilityArcInterface.getExtension() == null ? jReportItem.getReportExt() : utilityArcInterface.getExtension()));
        String fullFileName = getFullFileName(utilityArcInterface.getExtension());

        logger.info("saving file {filepath=" + filePath + fullFileName + "}");
        FileOutputStream fileOutputStream =
                new FileOutputStream(filePath + fullFileName);

        fileOutputStream.write(outdata);

        fileOutputStream.close();

    }


    public void setReportName(String reportName) {
        setFileName(reportName);
    }

    public void saveReport(byte[] data, String extension) throws IOException {

      /*  String fullFileName = getFullFileName(extension);

        byte[] outdata = archiveReport(data, fullFileName);

        fullFileName = getFullFileName((utilityArcInterface.getExtension() == null ? extension : utilityArcInterface.getExtension()));

        logger.info("saving file {filepath=" + filePath + fullFileName + "}");
        FileOutputStream fileOutputStream =
                new FileOutputStream(filePath + fullFileName);

        fileOutputStream.write(outdata);

        fileOutputStream.close();    */
    }
}
